<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


<%@page import="org.apache.struts.tiles.taglib.GetAttributeTag"%><script type="text/javascript">
	/**
	 * Activates the edit and delete button.
	 */
	function enableButtons() {
		document.getElementById("showButton").disabled = false;
		document.getElementById("editButton").disabled = false;
		document.getElementById("deleteButton").disabled = false;
	}

	/**
	 * Deactivates the show, edit and delete button.
	 */
	function deactivateButtons() {
		document.getElementById("showButton").disabled = true;
		document.getElementById("editButton").disabled = true;
		document.getElementById("deleteButton").disabled = true;
	}

	/**
	* Set the Radio-Buttons Invisble
	*/
	function invisbleRadio() {
		if(document.equipmentForm.selectedKey.value==null){
			for (i=0; i<document.equipmentForm.selectedKey.length; i++){
				document.equipmentForm.selectedKey[i].style.display = "none";
			}
		}else{
			document.equipmentForm.selectedKey.style.display ="none";
		}
	}

	/**
	* Realize the line-chooser
	*/
	function selectRow(equipId) {
		document.getElementById(equipId).className = "markedRow";
		// all others in evenRow or oddRow
		var classOfRow = 'oddRow';
		if(document.equipmentForm.selectedKey.value==null){
			for (i=0; i<document.equipmentForm.selectedKey.length; i++){
				if(classOfRow=='evenRow'){
					classOfRow='oddRow';
				}else{
					classOfRow='evenRow';
				}
				if (document.equipmentForm.selectedKey[i].value==equipId){
					document.equipmentForm.selectedKey[i].checked = true;
				}else{
					document.getElementById(document.equipmentForm.selectedKey[i].value).className = classOfRow;
				}
			}
		}else{
			document.equipmentForm.selectedKey.checked = true;
		}
		enableButtons();
	}
</script>

<html:form action="/adEquipment">
	<span style="color: #FF0000; size: 14pt;"> <bean:message key="${sessionScope.equipmentForm.errorCode}" /></span><br />
	<h1><bean:message key="heading.equipmentList" /></h1>
	<p><bean:message key="text.equipmentList" /></p>

	<table class="listTable" style="width: 500px;">
		<tr>
			<th style="width: 30px;">&nbsp;</th>
		<th><bean:message key="label.equipment" /></th>			
			<th><bean:message key="label.manufactureCompany" /></th>
			<th><bean:message key="label.yearOfManufacture" /></th>		
		</tr>
		<c:forEach var="equipment" items="${sessionScope.equipmentForm.equipments}"
			varStatus="rowStatus">
			<tr id="${equipment.equipmentId}" class="${(rowStatus.count % 2 == 0) ? 'oddRow' : 'evenRow'}"
				onclick="selectRow(${equipment.equipmentId})">
				<td style="width: 30px; text-align: center;">
					<html:radio
						property="selectedKey" value="${equipment.equipmentId}" />
				</td>
				<td>${equipment.modelName}</td>
				<td>${equipment.manufactureCompany}</td>
				<td>${equipment.yearOfManufacture}</td>
			</tr>
		</c:forEach>
	</table>
	<html:submit styleId="showButton" property="method">
		<bean:message key="button.show" />
	</html:submit>
	<html:submit styleId="createButton" property="method">
		<bean:message key="button.create" />
	</html:submit>
	<html:submit styleId="editButton" property="method">
		<bean:message key="button.edit" />
	</html:submit>
	<html:submit styleId="deleteButton" property="method">
		<bean:message key="button.delete" />
	</html:submit>
</html:form>